#pragma once
#include "event_handler.h"
#include "http_request_dispatcher.h"

class LocalServer
{
public:
	explicit LocalServer(int port) : m_port(port) { Init(); }
	explicit LocalServer(int port, EventHandler* handler) : m_port(port), m_pEvHandler(handler) { Init(); }
	virtual~LocalServer();
	virtual void SetEventHandler(EventHandler* handler);
	virtual void Start();
	virtual void Stop();

protected:
	virtual void DoOpen();
	virtual void DoClose();
	virtual bool Init();

protected:
	int m_port;
	EventHandler* m_pEvHandler;
	event_base* m_pEvBase = nullptr;
	evhttp* m_pEvHttp = nullptr;
	//bind the host ip default
	const char* BIND_HOST = "0.0.0.0";
	bool m_inited = false;
};

